package Messages;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * this class implements the subscriber can extend lending db
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */



public class MeassageActivitiyinit {
	
/**
 * constractor of this class get the client 	
 */
	private ConnectionToClient client;

	public MeassageActivitiyinit(ConnectionToClient client) {
		// TODO Auto-generated constructor stub
	this.client= client;
	
	}
	
/**
 * method that initsilaizing the activity report	
 * @throws SQLException
 * @throws IOException
 */
	
public void ActivityReportinit() throws SQLException, IOException
	
	{
		
	
	
		
		SQLConnection sc = new SQLConnection();
		
		PreparedStatement day = sc.getConnection().prepareStatement("SELECT * FROM db1.activity;");
		PreparedStatement selected = sc.getConnection().prepareStatement("SELECT * FROM db1.activemonth");
		PreparedStatement ps = sc.getConnection().prepareStatement("SELECT DISTINCT date FROM activity;");

		sc.getConnection().setAutoCommit(true);
		
		
		
		
		ResultSet dayrsrs=day.executeQuery();
		ArrayList<Object> senddays = new ArrayList<Object>();
		senddays.add("activityday");
	
		while(dayrsrs.next())
        {	
	    	senddays.add(dayrsrs.getInt(1));
	    	senddays.add(dayrsrs.getInt(2));
	    	senddays.add(dayrsrs.getInt(3));
	    	senddays.add(dayrsrs.getInt(4));
	    	senddays.add(dayrsrs.getInt(5));
	    	senddays.add(dayrsrs.getInt(6));
	    	senddays.add(dayrsrs.getDate(7));
        }
        	
		
    	ResultSet selectedrs=selected.executeQuery();
    	
    	senddays.add("activityselected");

    	while(selectedrs.next())
        {	
			senddays.add(selectedrs.getInt(1));
			senddays.add(selectedrs.getInt(2));
			senddays.add(selectedrs.getInt(3));
			senddays.add(selectedrs.getInt(4));
			senddays.add(selectedrs.getInt(5));
			senddays.add(selectedrs.getInt(6));
			senddays.add(selectedrs.getDate(7));
        }
        
		
		
      	ResultSet psrs=ps.executeQuery();
      
      		senddays.add("activitydate");
    	
    		while(psrs.next())
            {	
    			senddays.add(psrs.getDate(1));
            }
            
            client.sendToClient(senddays);
		
		
		
		
		
		
		
}




}